<template>
  <div class="presslist">
    <el-form
      ref="searchForm"
      :inline="true"
      :model="searchWhere"
      class="demo-form-inline"
      style="margin-top:-15px">
      <el-form-item label="出版社" prop="pressName">
        <el-input v-model="searchWhere.press" placeholder="出版社"> </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="fetchDate">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="presslist" highlight-current-row @current-change="CurrentPage" style="width: 100%" max-height="550">
      <el-table-column fixed type="index" label="序号" width="60">
      </el-table-column>
      <el-table-column prop="pressName" label="出版社名称" width="180">
      </el-table-column>
      <el-table-column prop="pressAddress" label="出版社地址" width="270">
      </el-table-column>
      <el-table-column prop="code" label="邮编" width="110">
      </el-table-column>
      <el-table-column prop="chargePerson" label="负责人" width="90">
      </el-table-column>
      <el-table-column prop="phone" label="电话" width="150">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="prev, pager, next"
      :total="total"
    ></el-pagination>
  </div>
</template>
<script>
import pressApi from "@/api/press";
export default {
  data() {
    return {
      form: {
        pressName:'',
        pressAddress:'',
        code:'',
        chargePerson:'',
        phone:''
      },
      presslist: [],
      total: 0,
      currentPage: 1,
      pageSize: 10,
      searchWhere: {
        pressName: ""
      }
    };
  },
  filters: {
    bookTypeFilter(type) {
      const booktypeobj = bookTypeOptions.find((obj) => obj.type === type);
      return booktypeobj ? booktypeobj.name : null;
    },
  },
  created() {
    this.fetchDate();
  },
  methods: {
    CurrentPage(currentRow,oldCurrentRow){
      /* console.log(currentRow) */
      this.$emit('sendData',currentRow)
    },
    addHandle(){
      this.dialogFormVisible=true
      this.$nextTick(()=>{
        this.$refs['addForm'].resetFields()
      })  
    },
    fetchDate() {
      // pressApi.getBookInfoList().then((response) => {
      pressApi
        .search(this.currentPage, this.pageSize, this.searchWhere)
        .then((response) => {
          const resp = response.data;
          console.log(resp.data.rows);
          this.presslist = resp.data.rows;
          this.total = resp.data.total;
        });
    },
    handleSizeChange(size) {
      this.pageSize = size;
      console.log(`每页${size}条`);
      this.fetchDate();
    },
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage;
      console.log(`当前页：${currentPage}`);
      this.fetchDate();
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  }
};
</script>
<style scoped>
</style>
